<template>
  <div id="man" style="width: 40%; height: 400px"></div>
</template>

<script>
import * as echarts from "echarts";
import { orderAll } from "../../api/hjn/index.js";
export default {
  mounted() {
    orderAll(1, 5).then((ok) => {
      console.log(ok.data.records);
      let bdata = () => {
        
        let arr2=[]
        for(var v of ok.data.records){
          let sum = 0;
          sum = v.oriprice * v.bnum;
          let obj = {};
          for (var item in v) {
            if (item === "proname") {
              obj["value"] = sum;
              obj["name"] = v[item];
            }
            
          }
          arr2.push(obj)
        }
        
        return arr2;
      };
      echartb(bdata);
    });

    let echartb = (bdata) => {
      var chartDom = document.getElementById("man");
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: "销售金额占比",
          left: "6%",
          textStyle: {
            color: "#666",
            fontWeight: "normal",
            fontSize: "18px",
          },
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
            },
            data: bdata(),
          },
        ],
      };

      option && myChart.setOption(option);
    };
  },
};
</script>

<style>
</style>